package conceptmaniax.hotelapp.util.sync;

import android.app.Activity;
import android.os.Handler;

public class ProgressWriteListener implements WriteListener {
	
	private Handler progressBarHandler;
	private long bytesMax;
	private Activity activity;
	private float weightedPercent;
	private int progress;
	private int currentPercent;
	
	public ProgressWriteListener(Activity activity, Handler progressBarHandler, float weightedPercent, int progress, long bytesMax) {
		this.activity = activity;
		this.progressBarHandler = progressBarHandler;
		this.weightedPercent = weightedPercent;
		this.progress = progress;
		this.bytesMax = bytesMax;
	}
	
	@Override
	public void registerWrite(final long bytesWritten) {
		int currentPercentTmp = (int) (0.5d + ((double) bytesWritten/(double) bytesMax) * weightedPercent * 100) + progress;
		if (currentPercentTmp != currentPercent) {
			currentPercent = currentPercentTmp;
			//new ProgressBarPoster().post(activity, progressBarHandler, currentPercent);
		}
	}
}
